package com.ciquan.server.service.impl;

import com.ciquan.server.bean.BusinessStatus;
import com.ciquan.server.dao.BusinessStatusMapper;
import com.ciquan.server.service.BusinessStatusService;
import com.ciquan.server.util.DateUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by kakalee on 16/3/8.
 */
@Service
public class BusinessStatusServiceImpl implements BusinessStatusService{

    private Logger logger = Logger.getLogger(this.getClass());

    @Resource
    private BusinessStatusMapper businessStatusMapper;


    @Override
    public int insert(BusinessStatus businessStatus) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("date", DateUtils.formatToString(businessStatus.getDate(), DateUtils.yyyyMMdd));
        map.put("type", businessStatus.getType());
        List<BusinessStatus> businessStatuses = businessStatusMapper.selectList(map);
        if(businessStatuses.size() > 0) {
            return 0;
        }

        else  {
            try {
                return businessStatusMapper.insert(businessStatus);
            } catch (Exception e) {
                logger.error(e);
            }
        }
        return 0;

    }

    @Override
    public List<BusinessStatus> selectList(Map<String, Object> map) {
        return businessStatusMapper.selectList(map);
    }
}
